package com.voja.mrvica2.remoteimage;

import java.io.FileOutputStream;


import com.voja.mrvica2.App;
import com.voja.mrvica2.Index;
import com.voja.mrvica2.R;
import com.voja.mrvica2.Zoom;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;

public class RemoteImageZoom implements View.OnClickListener {

    public static final String BITMAP_KEY      = "bitmap";
    public static final String BITMAP_FILENAME = "tmpimage";
    
    Index activity;
    
    public RemoteImageZoom(Index activity) {
        this.activity = activity;
    }
    
    @Override
    public void onClick(View v) {
        RemoteImageView riv      = (RemoteImageView)v;
        
        App.setContext(activity);
        if (riv.bitmap != null) {
            try {
                riv.findViewById(R.id.remoteThrobber).setVisibility(View.VISIBLE);
                FileOutputStream f = activity.openFileOutput(BITMAP_FILENAME, Context.MODE_PRIVATE);
                riv.bitmap.compress(Bitmap.CompressFormat.JPEG, 90, f);
                f.close();
                
                Intent i = new Intent(activity, Zoom.class);
                activity.startActivity(i);
                
            } catch (Exception e) {
                App.alert(e.getMessage());
            } finally {
                riv.findViewById(R.id.remoteThrobber).setVisibility(View.GONE);
            }
        }
    }
}
